﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoliderStateShoot : NState<SlgEntitySoldier>
{
    public void Enter(SlgEntitySoldier entity, params object[] args)
    {
        if(entity.m_pVo.config.soliderType == SlgFightDef.c_iArmyType_Arrow)
        {
            for (int i = 0; i < SlgFightDef.IArrowShootNum; i++)
            {
                SlgBattleMgr.Instance.AddTimer(() =>
                {
                    entity.PlayAction(SlgFightDef.c_sAction_A2, false);
                    SlgEntityBullet bulletEntity = BattleEntityFactory.Instance.CreateBtEntity<SlgEntityBullet>();
                    bulletEntity.OnCreate(FlyItemStateType.Parabola,
                                          9001,
                                          entity.m_pGameObj.transform.position,
                                          SlgFightUtil.GetShootTarget(entity),
                                          15,
                                          UnityEngine.Random.Range(40,45),
                                          false);

                    entity.InsertChild(bulletEntity.Id);
                    bulletEntity.SetParent(entity);
                }, SlgFightDef.FArrowShootGap * i);
            }

            SlgBattleMgr.Instance.AddTimer(() =>
            {
                entity.ChangeState(SlgSoldierState.c_sSoldier_Idle);

            }, SlgFightDef.FArrowShootGap * SlgFightDef.IArrowShootNum);
        }
        else if(entity.m_pVo.config.soliderType == SlgFightDef.c_iArmyType_Tank)
        {
            for (int i = 0; i < SlgFightDef.IArrowShootNum; i++)
            {
                SlgBattleMgr.Instance.AddTimer(() =>
                {
                    entity.PlayAction(SlgFightDef.c_sAction_A2, false);
                    SlgEntityBullet bulletEntity = BattleEntityFactory.Instance.CreateBtEntity<SlgEntityBullet>();
                    bulletEntity.OnCreate(FlyItemStateType.Parabola,
                                          11003,
                                          entity.m_pGameObj.transform.position,
                                          SlgFightUtil.GetShootTarget(entity),
                                          15,
                                          UnityEngine.Random.Range(40, 45),
                                          false);

                    entity.InsertChild(bulletEntity.Id);
                    bulletEntity.SetParent(entity);
                }, SlgFightDef.FArrowShootGap * i);
            }

            SlgBattleMgr.Instance.AddTimer(() =>
            {
                entity.ChangeState(SlgSoldierState.c_sSoldier_Idle);

            }, SlgFightDef.FArrowShootGap * SlgFightDef.IArrowShootNum);
        }

    }

    public void Execute(SlgEntitySoldier entity, params object[] args)
    {
        
    }

    public void Exit(SlgEntitySoldier entity, params object[] args)
    {
        
    }

    public bool OnMessage(SlgEntitySoldier entity, MessageBody message)
    {
        return false;
    }
}
